package com.guiji.job.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.guiji.job.vo.JobLabelVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.guiji.common.annotation.RepeatSubmit;
import com.guiji.common.annotation.Log;
import com.guiji.common.core.controller.BaseController;
import com.guiji.common.core.domain.AjaxResult;
import com.guiji.common.enums.BusinessType;
import com.guiji.job.vo.JobMarkRecordVo;
import com.guiji.job.bo.JobMarkRecordQueryBo;
import com.guiji.job.bo.JobMarkRecordAddBo;
import com.guiji.job.bo.JobMarkRecordEditBo;
import com.guiji.job.service.IJobMarkRecordService;
import com.guiji.common.utils.poi.ExcelUtil;
import com.guiji.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务打标记录Controller
 *
 * @author 钟维澎（四月）
 * @date 2021-07-02
 */
@Api(value = "任务打标记录控制器", tags = {"任务打标记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/markRecord/markRecord")
public class JobMarkRecordController extends BaseController {

    private final IJobMarkRecordService iJobMarkRecordService;

    /**
     * 查询任务打标记录列表
     */
    @ApiOperation("查询任务打标记录列表")
    @PreAuthorize("@ss.hasPermi('markRecord:markRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<JobMarkRecordVo> list(@Validated JobMarkRecordQueryBo bo) {
        return iJobMarkRecordService.queryPageList(bo);
    }

    /**
     * 导出任务打标记录列表
     */
    @ApiOperation("导出任务打标记录列表")
    @PreAuthorize("@ss.hasPermi('markRecord:markRecord:export')")
    @Log(title = "任务打标记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<JobMarkRecordVo> export(@Validated JobMarkRecordQueryBo bo) {
        List<JobMarkRecordVo> list = iJobMarkRecordService.queryList(bo);
        ExcelUtil<JobMarkRecordVo> util = new ExcelUtil<JobMarkRecordVo>(JobMarkRecordVo.class);
        return util.exportExcel(list, "任务打标记录");
    }

    /**
     * 获取任务打标记录详细信息
     */
    @ApiOperation("获取任务打标记录详细信息")
    //@PreAuthorize("@ss.hasPermi('markRecord:markRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<JobLabelVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {

    	if(ObjectUtil.isNull(id)){
    		return AjaxResult.error("入参为空",null);
		}
        return AjaxResult.success("成功",iJobMarkRecordService.queryJobLabelVo(id));
    }


	/**
     * 新增任务打标记录
     */
    @ApiOperation("新增任务打标记录")
    @PreAuthorize("@ss.hasPermi('markRecord:markRecord:add')")
    @Log(title = "任务打标记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody JobMarkRecordAddBo bo) {
        return toAjax(iJobMarkRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改任务打标记录
     */
    @ApiOperation("修改任务打标记录")
    @PreAuthorize("@ss.hasPermi('markRecord:markRecord:edit')")
    @Log(title = "任务打标记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody JobMarkRecordEditBo bo) {
        return toAjax(iJobMarkRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除任务打标记录
     */
    @ApiOperation("删除任务打标记录")
    @PreAuthorize("@ss.hasPermi('markRecord:markRecord:remove')")
    @Log(title = "任务打标记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iJobMarkRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
